package com.tuju.jetpackfirstdemo.adapter

import android.view.View
import android.view.ViewGroup
import com.tuju.jetpackfirstdemo.R
import com.tuju.jetpackfirstdemo.base.baseadapter.BaseRecyclerViewAdapter
import com.tuju.jetpackfirstdemo.base.baseadapter.BaseRecyclerViewHolder
import kotlinx.android.synthetic.main.item_schedu_date.view.*

class ScheduleDateAdapter(val listener: ClickCallBack) : BaseRecyclerViewAdapter<String>() {
    var selectPosition: Int = 0

    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): BaseRecyclerViewHolder<String> {
        return ViewHolder(getView(parent, R.layout.item_schedu_date))
    }

    inner class ViewHolder(view: View) : BaseRecyclerViewHolder<String>(view) {
        override fun onBaseBindViewHolder(t: String, position: Int) {
            if (position == 0) {
                view.tv_date.text = "今"
            } else {
                view.tv_date.text = t
            }
            view.setOnClickListener {
                listener.onDateItemClick(position, t)
            }
            //选中状态
            view.tv_date.isSelected = (selectPosition == position)
        }
    }

    interface ClickCallBack {
        fun onDateItemClick(position: Int, date: String)
    }

}